home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_bas / pbc32.zip / PBC$BAS.ZIP / BINSEEKL.BAS < prev    next >
BASIC Source File  |  1996-04-10  |  1KB  |  39 lines

  1. '   +----------------------------------------------------------------------+
  2. '   |                                                                      |
  3. '   |   PBClone  (C) Copyright 1996 Charon Software, All Rights Reserved   |
  4. '   |                                                                      |
  5. '   +----------------------------------------------------------------------+
  6.  
  7. SUB BinSeekL (Array&(), Elements%, Target&, Posn%)
  8.    IF Elements% = 0 THEN
  9.       Posn% = -1
  10.    ELSE
  11.       Top% = 1
  12.       Bottom% = Elements% + 1
  13.       OldPlace% = Bottom%
  14.       DO
  15.          Place% = (Top% + Bottom%) \ 2
  16.          IF Place% = OldPlace% THEN
  17.             NotThere% = -1
  18.          ELSEIF Array&(Place%) = Target& THEN
  19.             Found% = -1
  20.          ELSEIF Array&(Place%) > Target& THEN
  21.             Bottom% = Place%
  22.          ELSE
  23.             Top% = Place%
  24.          END IF
  25.          OldPlace% = Place%
  26.       LOOP UNTIL Found% OR NotThere%
  27.       IF NotThere% THEN
  28.          IF Elements% = UBOUND(Array&) THEN
  29.             Posn% = 0
  30.          ELSE
  31.             IF Target& > Array&(Place%) THEN Place% = Place% + 1
  32.             Posn% = -Place%
  33.          END IF
  34.       ELSE
  35.          Posn% = Place%
  36.       END IF
  37.    END IF
  38. END SUB
  39.